package com.example.goods.service.impl;

import com.example.goods.bean.User;
import com.example.goods.common.ResultResponse;
import com.example.goods.repository.UserRepository;
import com.example.goods.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * Created by IntelliJ IDEA.
 *用户模块
 * @author ouyangzhixiang
 * @date 2018/7/4
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService {
    private final UserRepository userRepository;

    /**
     * 用户登录
     * @param username 用户名
     * @param password 用户密码
     * @return
     */
    @Override
    public ResultResponse<User> login(String username, String password) {
        User user = userRepository.findByUsernameAndPassword(username, password);
        if (user == null) {
            return ResultResponse.createByErrorMessage("用户名或密码错误");
        }
        return ResultResponse.createBySuccessMessage("成功",user);
    }
}
